class FightController extends AttackController;

var float downTime;
var float StartSeconds;
var bool hadBlocked;
var float blockDelay;
var float blockTime;
var float weaponTime;

DefaultProperties
{
	downTime = 1;       // algemene cooldown tijd
	blockDelay = 0.3;   // de tijd die ertussen zit voor het opnieuw blocken
	blockTime = 1.0;    // de tijd dat hij blijft blocken
	weaponTime = 0.7;   // cooldowntijd voor t wapen
}

function whattodonext()
{
	local float r;
	r = Rand(100);
	
	if(r>50){
		if(CanDo()){GotoState('attack');}
	}else{
		if(CanDo(true)) {GotoState('block');}
		else if(CanDo()){GotoState('attack');}
	}
}

auto state Wait
{
	event Tick(float delta)
	{
		whattodonext();
	}
	Begin:
		`log('wait');
}

state Block
{
	event Tick(float deltatime){
		if(WorldInfo.TimeSeconds > (StartSeconds+downTime-blockDelay))
			Done();
	}

	Begin:
		`log('block');
		FightPawn(Pawn).PlayBlockAnimation();
		setDowntime(blockTime);
}

state Attack
{
	Begin:
		`log('attack');
		Pawn.StartFire(0);
		Pawn.StopFire(0);
		setDowntime(weaponTime);
		Done();
}

function setDowntime(float time)
{
	StartSeconds = WorldInfo.TimeSeconds;
	downTime = time;
}

function bool CanDo(optional bool b)
{
	if(hadBlocked && !b)
		return (WorldInfo.TimeSeconds > (StartSeconds+downTime-blockDelay));
	else
		return (WorldInfo.TimeSeconds > (StartSeconds+downTime));
}

function Done()
{
	GotoState('Wait');
}